import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import { createPinia } from 'pinia'

//导入axios
import axios from "axios"
//导入element-plus
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
//导入element-plus图标
import * as ElementPlusIconsVue from '@element-plus/icons-vue'

//axios统一配置
axios.defaults.baseURL='http://127.0.0.1:8888/'
//每次发送请求都将token放在headers中，携带着一起向后端请求数据，后端安全过滤器拦截，并解析token
axios.interceptors.request.use(config=>{
    const token=sessionStorage.getItem('token');
    if(token!=null){
        config.headers.Authorization=token;
    }
    return config;
})

const app = createApp(App)

app.use(createPinia())
app.use(router)
app.use(ElementPlus)

//app.config.globalProperties.$message

//使用element-plus图标
for(const [key,component] of Object.entries(ElementPlusIconsVue)){
    app.component(key,component)
}
app.mount('#app')
